package com.example.tableapplication.application;

import android.app.Application;
import android.content.Intent;
import android.content.SharedPreferences;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.RadioButton;

public class MyApplication extends Application {


    //登录界面的用户名密码字段
    private String login_username;
    private String login_password;
    private Boolean save_password;
    private Boolean login_state=false;

//    //扫描设置的全局变量
//    private static Button bt_scan;
//    private Button bt_make;
//    private Button bt_save;
//    private static final String TAG = "MainActivity_1";
//    private ImageView iv_qr;
//    private EditText et_qr_content;
//    private EditText et_qr_title;
//    private EditText et_qr_des;
//    private CheckBox cb_show_title;
//    private CheckBox cd_show_des;
//    private CheckBox cb_show_ding;
//    private CheckBox cb_show_custom_ding;
//    private CheckBox cb_show_flash;
//    private CheckBox cb_show_album;
//    private CheckBox cb_only_center;
//    private CheckBox cb_create_add_water;
//    private CheckBox cb_crop_image;
//    private CheckBox cb_show_zoom;
//    private CheckBox cb_auto_zoom;
//    private CheckBox cb_finger_zoom;
//    private CheckBox cb_double_engine;
//    private CheckBox cb_loop_scan;
//    private CheckBox cb_auto_light;
//    private CheckBox cb_have_vibrator;
//    private RadioButton rb_qrcode;
//    private RadioButton rb_bcode;
//    private RadioButton rb_all;
//    private RadioButton rb_screen_sx;
//    private RadioButton rb_screen_hx;
//    private RadioButton rb_screen_auto;
//    private EditText et_loop_scan_time;
//    private RadioButton rb_scanline_radar;
//    private RadioButton rb_scanline_grid;
//    private RadioButton rb_scanline_hybrid;
//    private RadioButton rb_scanline_line;
//    private Boolean myState=false;


    //扫描设置的全局变量
    private static final String TAG = "MainActivity_1";
//    private ImageView iv_qr;
    private String et_qr_content;
    private String et_qr_title;
    private String et_qr_des;
    private String cb_show_title;
    private String cd_show_des;
    private String cb_show_ding;
    private String cb_show_custom_ding;
    private String cb_show_flash;
    private String cb_show_album;
    private String cb_only_center;
    private String cb_create_add_water;
    private String cb_crop_image;
    private String cb_show_zoom;
    private String cb_auto_zoom;
    private String cb_finger_zoom;
    private String cb_double_engine;
    private String cb_loop_scan;
    private String cb_auto_light;
    private String cb_have_vibrator;
    private String rb_qrcode;
    private String rb_bcode;
    private String rb_all;
    private String rb_screen_sx;
    private String rb_screen_hx;
    private String rb_screen_auto;
    private String et_loop_scan_time;
    private String rb_scanline_radar;
    private String rb_scanline_grid;
    private String rb_scanline_hybrid;
    private String rb_scanline_line;
    private Boolean myState=false;

    //数据源配置的全局变量
    private String et_dbadress;
    private String et_dbport;
    private String et_dbname;
    private String et_dbusername;
    private String et_dbpassword;
    private Boolean dbsource_state=false;

    //登陆界面的用户名密码属性的getter和setter
    public String getLogin_username() {
        return login_username;
    }

    public void setLogin_username(String login_username) {
        this.login_username = login_username;
    }

    public String getLogin_password() {
        return login_password;
    }

    public void setLogin_password(String login_password) {
        this.login_password = login_password;
    }

    public Boolean getSave_password() {
        return save_password;
    }

    public void setSave_password(Boolean save_password) {
        this.save_password = save_password;
    }

    public Boolean getLogin_state() {
        return login_state;
    }

    public void setLogin_state(Boolean login_state) {
        this.login_state = login_state;
    }

    //数据源配置属性的getter和setter
    public String getEt_dbadress() {
        return et_dbadress;
    }

    public void setEt_dbadress(String et_dbadress) {
        this.et_dbadress = et_dbadress;
    }

    public String getEt_dbport() {
        return et_dbport;
    }

    public void setEt_dbport(String et_dbport) {
        this.et_dbport = et_dbport;
    }

    public String getEt_dbname() {
        return et_dbname;
    }

    public void setEt_dbname(String et_dbname) {
        this.et_dbname = et_dbname;
    }

    public String getEt_dbusername() {
        return et_dbusername;
    }

    public void setEt_dbusername(String et_dbusername) {
        this.et_dbusername = et_dbusername;
    }

    public String getEt_dbpassword() {
        return et_dbpassword;
    }

    public void setEt_dbpassword(String et_dbpassword) {
        this.et_dbpassword = et_dbpassword;
    }

    public Boolean getDbsource_state() {
        return dbsource_state;
    }

    public void setDbsource_state(Boolean dbsource_state) {
        this.dbsource_state = dbsource_state;
    }

    //扫描设置属性的getter和setter
    public String getEt_qr_content() {
        return et_qr_content;
    }

    public void setEt_qr_content(String et_qr_content) {
        this.et_qr_content = et_qr_content;
    }

    public String getEt_qr_title() {
        return et_qr_title;
    }

    public void setEt_qr_title(String et_qr_title) {
        this.et_qr_title = et_qr_title;
    }

    public String getEt_qr_des() {
        return et_qr_des;
    }

    public void setEt_qr_des(String et_qr_des) {
        this.et_qr_des = et_qr_des;
    }

    public String getCb_show_title() {
        return cb_show_title;
    }

    public void setCb_show_title(String cb_show_title) {
        this.cb_show_title = cb_show_title;
    }

    public String getCd_show_des() {
        return cd_show_des;
    }

    public void setCd_show_des(String cd_show_des) {
        this.cd_show_des = cd_show_des;
    }

    public String getCb_show_ding() {
        return cb_show_ding;
    }

    public void setCb_show_ding(String cb_show_ding) {
        this.cb_show_ding = cb_show_ding;
    }

    public String getCb_show_custom_ding() {
        return cb_show_custom_ding;
    }

    public void setCb_show_custom_ding(String cb_show_custom_ding) {
        this.cb_show_custom_ding = cb_show_custom_ding;
    }

    public String getCb_show_flash() {
        return cb_show_flash;
    }

    public void setCb_show_flash(String cb_show_flash) {
        this.cb_show_flash = cb_show_flash;
    }

    public String getCb_show_album() {
        return cb_show_album;
    }

    public void setCb_show_album(String cb_show_album) {
        this.cb_show_album = cb_show_album;
    }

    public String getCb_only_center() {
        return cb_only_center;
    }

    public void setCb_only_center(String cb_only_center) {
        this.cb_only_center = cb_only_center;
    }

    public String getCb_create_add_water() {
        return cb_create_add_water;
    }

    public void setCb_create_add_water(String cb_create_add_water) {
        this.cb_create_add_water = cb_create_add_water;
    }

    public String getCb_crop_image() {
        return cb_crop_image;
    }

    public void setCb_crop_image(String cb_crop_image) {
        this.cb_crop_image = cb_crop_image;
    }

    public String getCb_show_zoom() {
        return cb_show_zoom;
    }

    public void setCb_show_zoom(String cb_show_zoom) {
        this.cb_show_zoom = cb_show_zoom;
    }

    public String getCb_auto_zoom() {
        return cb_auto_zoom;
    }

    public void setCb_auto_zoom(String cb_auto_zoom) {
        this.cb_auto_zoom = cb_auto_zoom;
    }

    public String getCb_finger_zoom() {
        return cb_finger_zoom;
    }

    public void setCb_finger_zoom(String cb_finger_zoom) {
        this.cb_finger_zoom = cb_finger_zoom;
    }

    public String getCb_double_engine() {
        return cb_double_engine;
    }

    public void setCb_double_engine(String cb_double_engine) {
        this.cb_double_engine = cb_double_engine;
    }

    public String getCb_loop_scan() {
        return cb_loop_scan;
    }

    public void setCb_loop_scan(String cb_loop_scan) {
        this.cb_loop_scan = cb_loop_scan;
    }

    public String getCb_auto_light() {
        return cb_auto_light;
    }

    public void setCb_auto_light(String cb_auto_light) {
        this.cb_auto_light = cb_auto_light;
    }

    public String getCb_have_vibrator() {
        return cb_have_vibrator;
    }

    public void setCb_have_vibrator(String cb_have_vibrator) {
        this.cb_have_vibrator = cb_have_vibrator;
    }

    public String getRb_qrcode() {
        return rb_qrcode;
    }

    public void setRb_qrcode(String rb_qrcode) {
        this.rb_qrcode = rb_qrcode;
    }

    public String getRb_bcode() {
        return rb_bcode;
    }

    public void setRb_bcode(String rb_bcode) {
        this.rb_bcode = rb_bcode;
    }

    public String getRb_all() {
        return rb_all;
    }

    public void setRb_all(String rb_all) {
        this.rb_all = rb_all;
    }

    public String getRb_screen_sx() {
        return rb_screen_sx;
    }

    public void setRb_screen_sx(String rb_screen_sx) {
        this.rb_screen_sx = rb_screen_sx;
    }

    public String getRb_screen_hx() {
        return rb_screen_hx;
    }

    public void setRb_screen_hx(String rb_screen_hx) {
        this.rb_screen_hx = rb_screen_hx;
    }

    public String getRb_screen_auto() {
        return rb_screen_auto;
    }

    public void setRb_screen_auto(String rb_screen_auto) {
        this.rb_screen_auto = rb_screen_auto;
    }

    public String getEt_loop_scan_time() {
        return et_loop_scan_time;
    }

    public void setEt_loop_scan_time(String et_loop_scan_time) {
        this.et_loop_scan_time = et_loop_scan_time;
    }

    public String getRb_scanline_radar() {
        return rb_scanline_radar;
    }

    public void setRb_scanline_radar(String rb_scanline_radar) {
        this.rb_scanline_radar = rb_scanline_radar;
    }

    public String getRb_scanline_grid() {
        return rb_scanline_grid;
    }

    public void setRb_scanline_grid(String rb_scanline_grid) {
        this.rb_scanline_grid = rb_scanline_grid;
    }

    public String getRb_scanline_hybrid() {
        return rb_scanline_hybrid;
    }

    public void setRb_scanline_hybrid(String rb_scanline_hybrid) {
        this.rb_scanline_hybrid = rb_scanline_hybrid;
    }

    public String getRb_scanline_line() {
        return rb_scanline_line;
    }

    public void setRb_scanline_line(String rb_scanline_line) {
        this.rb_scanline_line = rb_scanline_line;
    }

    public Boolean getMyState() {
        return myState;
    }

    public void setMyState(Boolean myState) {
        this.myState = myState;
    }

    public void readManger(){
        //读取存储在本地的信息
        //创建SharedPreferences对象
        SharedPreferences sp = getSharedPreferences("info", MODE_PRIVATE);
        //获得保存在SharedPredPreferences中的用户名和密码
//        String service = sp.getString("service", "");
        //读取存储在本地的登录界面的用户名密码
        String login_userName = sp.getString("login_username", "");
        String login_passWord = sp.getString("login_password", "");
        Boolean save_passWord=sp.getBoolean("save_password",false);
        setLogin_username(login_userName);
        setLogin_password(login_passWord);
        setSave_password(save_passWord);
        setLogin_state(true);


        //读取存储在本地的数据源配置界面的数据
        String dbadress=sp.getString("db_adress","");
        String dbport=sp.getString("db_port","");
        String dbname=sp.getString("db_name","");
        String dbusername=sp.getString("db_username","");
        String dbpassword=sp.getString("db_password","");
        setEt_dbadress(dbadress);
        setEt_dbport(dbport);
        setEt_dbname(dbname);
        setEt_dbusername(dbusername);
        setEt_dbpassword(dbpassword);
        setDbsource_state(true);

        //读取存储在本地的扫描设置的各属性
        setEt_qr_content(sp.getString("et_qr_content",""));
        setEt_qr_title(sp.getString("et_qr_title",""));
        setEt_qr_des(sp.getString("et_qr_des",""));
        setCb_show_title(sp.getString("cb_show_title",""));
        setCd_show_des(sp.getString("cd_show_des",""));
        setCb_show_ding(sp.getString("cb_show_ding",""));
        setCb_show_custom_ding(sp.getString("cb_show_custom_ding",""));
        setCb_show_flash(sp.getString("cb_show_flash",""));
        setCb_show_album(sp.getString("cb_show_album",""));
        setCb_only_center(sp.getString("cb_only_center",""));
        setCb_create_add_water(sp.getString("cb_create_add_water",""));
        setCb_crop_image(sp.getString("cb_crop_image",""));
        setCb_show_zoom(sp.getString("cb_show_zoom",""));
        setCb_auto_zoom(sp.getString("cb_auto_zoom",""));
        setCb_finger_zoom(sp.getString("cb_finger_zoom",""));
        setCb_double_engine(sp.getString("cb_double_engine",""));
        setCb_loop_scan(sp.getString("cb_loop_scan",""));
        setCb_auto_light(sp.getString("cb_auto_light",""));
        setCb_have_vibrator(sp.getString("cb_have_vibrator",""));
        setRb_qrcode(sp.getString("rb_qrcode",""));
        setRb_bcode(sp.getString("rb_bcode",""));
        setRb_all(sp.getString("rb_all",""));
        setRb_screen_sx(sp.getString("rb_screen_sx",""));
        setRb_screen_hx(sp.getString("rb_screen_hx",""));
        setRb_screen_auto(sp.getString("rb_screen_auto",""));
        setEt_loop_scan_time(sp.getString("et_loop_scan_time",""));
        setRb_scanline_radar(sp.getString("rb_scanline_radar",""));
        setRb_scanline_grid(sp.getString("rb_scanline_grid",""));
        setRb_scanline_hybrid(sp.getString("rb_scanline_hybrid",""));
        setRb_scanline_line(sp.getString("rb_scanline_line",""));
        setMyState(sp.getBoolean("MyState",false));
    }

    /**
     *  保存用户名密码功能
     */
    public void saveManger(){
        //获取 输入的服务器内容
//        String inputService =  editText1.getText().toString();
        //勾选了保存密码逻辑
        SharedPreferences spf = getSharedPreferences("info", MODE_PRIVATE);
        SharedPreferences.Editor editor = spf.edit();
        if(save_password) {
            //获取 输入的密码信息
//            String inputPassword =  getLogin_password();
            editor.putString("login_password",getLogin_password());
        }else{
            //删除本地储存的密码
            editor.remove("login_password");
        }
        //保存页面信息到本地
//        editor.putString("service",inputService);
        editor.putBoolean("save_password",getSave_password());
        editor.putString("login_username",getLogin_username());

        //数据源配置信息
        editor.putString("db_adress",getEt_dbadress());
        editor.putString("db_port",getEt_dbport());
        editor.putString("db_name",getEt_dbname());
        editor.putString("db_username",getEt_dbusername());
        editor.putString("db_password",getEt_dbpassword());
        setDbsource_state(true);

        //扫描设置
        editor.putString("et_qr_content",getEt_qr_content());
        editor.putString("et_qr_title",getEt_qr_title());
        editor.putString("et_qr_des",getEt_qr_des());
        editor.putString("cb_show_title",getCb_show_title());
        editor.putString("cd_show_des",getCd_show_des());
        editor.putString("cb_show_ding",getCb_show_ding());
        editor.putString("cb_show_custom_ding",getCb_show_custom_ding());
        editor.putString("cb_show_flash",getCb_show_flash());
        editor.putString("cb_show_album",getCb_show_album());
        editor.putString("cb_only_center",getCb_only_center());
        editor.putString("cb_create_add_water",getCb_create_add_water());
        editor.putString("cb_crop_image",getCb_crop_image());
        editor.putString("cb_show_zoom",getCb_show_zoom());
        editor.putString("cb_auto_zoom",getCb_auto_zoom());
        editor.putString("cb_finger_zoom",getCb_finger_zoom());
        editor.putString("cb_double_engine",getCb_double_engine());
        editor.putString("cb_loop_scan",getCb_loop_scan());
        editor.putString("cb_auto_light",getCb_auto_light());
        editor.putString("cb_have_vibrator",getCb_have_vibrator());
        editor.putString("rb_qrcode",getRb_qrcode());
        editor.putString("rb_bcode",getRb_bcode());
        editor.putString("rb_all",getRb_all());
        editor.putString("rb_screen_sx",getRb_screen_sx());
        editor.putString("rb_screen_hx",getRb_screen_hx());
        editor.putString("rb_screen_auto",getRb_screen_auto());
        editor.putString("et_loop_scan_time",getEt_loop_scan_time());
        editor.putString("rb_scanline_radar",getRb_scanline_radar());
        editor.putString("rb_scanline_grid",getRb_scanline_grid());
        editor.putString("rb_scanline_hybrid",getRb_scanline_hybrid());
        editor.putString("rb_scanline_line",getRb_scanline_line());
        editor.putBoolean("MyState",getMyState());
        editor.commit();
    }

    @Override
    public void onCreate() {
        super.onCreate();
        readManger();
    }

}
